﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using RouterControl.IO;
using RouterControl.Whs.Wizards;
using RouterControl.Web;

namespace RouterControl.WhsAddIn.Wizards.SelectRouter
{
    public partial class PageWelcome : WizardPageClientBannerTop
    {
        private readonly log4net.ILog _log = log4net.LogManager.GetLogger(typeof(PageWelcome));

        private WizardMain ParentWizardMain
        {
            get { return (WizardMain)this.ParentWizard; }
        }

        public PageWelcome()
        {
            InitializeComponent();
        }

        public override void StartRealWork()
        {
            base.StartRealWork();

            // dump version information
            _log.Debug("Dumping version information...");

            try
            {
                // gather information
                var info = this.ParentWizardMain.UsageInfo;

                info.InstanceId = Whs.RouterControlRegistry.GetInstanceId();
                info.VersionId = RouterControlVersion.VersionId;
                info.ExitPage = GetType().Name;

                info.HomeServerVersion = FileVersionInfo.GetVersionInfo(Whs.ApplicationFolders.HomeServerDir + "\\HomeServerConsole.exe").FileVersion;
                info.UpnpStackVersion = FileVersionInfo.GetVersionInfo(Whs.ApplicationFolders.WindowsSystem32 + "\\upnp.dll").FileVersion;

                // write everything to the log
                RouterControlVersion.LogVersion(_log);

                _log.Info("Instance ID: " + info.InstanceId);

                _log.Info("Windows Home Server version: " + info.HomeServerVersion);
                _log.Info("Windows UPNP stack version: " + info.UpnpStackVersion);
            }
            catch (Exception e)
            {
                _log.Error("Failed to gather version information", e);
            }
        }

        private void PageWelcome_OkButtonClick(object sender, EventArgs e)
        {
            this.SetCurrentPage<PageAllowUpload>();
        }
    }
}